import Mock from 'mockjs'

// 有三个参数：请求路径 + 请求方式 + 回调返回值
/**
 * @description: 登录接口
 * @param {*} api
 * @param {*} post
 * @param {any} data
 * @return {*}
 */
Mock.mock('api/login', 'post', (data: any) => {
  let username = JSON.parse(JSON.parse(JSON.stringify(data)).body).username
  let password = JSON.parse(JSON.parse(JSON.stringify(data)).body).password
  if (username && password) {
    return Mock.mock({
      status: 200,
      data: {
        username,
        uid: 1,
        role: '超级管理员',
        token: 'this is a vue3 + ts + pinia project',
        lastTime: '2023-12-25 17:59:00',
        lastAddress: '北京市'
      },
      message: '登录成功！'
    })
  } else {
    return Mock.mock({
      status: 200,
      message: '登录失败！'
    })
  }
  // console.log(JSON.parse(JSON.stringify(data)), 'data');
  // console.log(JSON.parse(JSON.parse(JSON.stringify(data)).body), 'data');
})


/**
 * @description: 首页销量详情接口
 * @return {*}
 */

Mock.mock('api/sales', 'get', {
  code: 200,
  msg: '请求成功',
  items: [
    { brand: '华为', daySales: 100, monthSales: 1200, allSales: 1300 },
    { brand: '小米', daySales: 80, monthSales: 800, allSales: 880 },
    { brand: 'OPPO', daySales: 50, monthSales: 300, allSales: 350 },
    { brand: '苹果', daySales: 110, monthSales: 1600, allSales: 1710 },
    { brand: 'vivo', daySales: 20, monthSales: 1000, allSales: 1200 },
    { brand: '红米', daySales: 30, monthSales: 600, allSales: 630 },
    { brand: '魅族', daySales: 5, monthSales: 110, allSales: 115 },
    { brand: '魅族', daySales: 5, monthSales: 110, allSales: 115 },
    { brand: '魅族', daySales: 5, monthSales: 110, allSales: 115 },
    { brand: '魅族', daySales: 5, monthSales: 110, allSales: 115 },
    { brand: '魅族', daySales: 5, monthSales: 110, allSales: 115 },
    { brand: '魅族', daySales: 5, monthSales: 110, allSales: 115 },
    { brand: '魅族', daySales: 5, monthSales: 110, allSales: 115 },
  ]
})

/**
 * @description: 首页订单接口
 * @return {*}
 */
Mock.mock('api/order', 'post', {
  code: 200,
  msg: '请求成功',
  "data|6": [
    {
      id: "@id",
      "number|20-200": 20,
    }
  ]
})


/**
 * @description: 用户管理列表接口
 * @return {*}
 */

Mock.mock('api/user', 'post', {
  code: 200,
  msg: '请求成功',
  "data|22": [
    {
      "id|+1": 1,
      name: "@cname",
      role: '管理员',
      "tel": /13\d{9}/,
      "pic": `@dataImage('80x80','../assets/image/user/sb.png')`
    }
  ]
})